package com.chromatic.competition.view.account;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.chromatic.competition.R;
import com.chromatic.competition.service.UserServiceImpl;
import com.chromatic.competition.utils.NetworkUtils;

public class LoginActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        Button loginButton = findViewById(R.id.login_button);
        Button gotoRegisterButton = findViewById(R.id.goto_register_button);

//        UpdateService.checkVersion(LoginActivity.this);
        loginButton.setOnClickListener(view -> {
            EditText usernameEditText = findViewById(R.id.username_editText);
            EditText passwordEditText = findViewById(R.id.password_editText);
            String username = usernameEditText.getText().toString().trim();
            String password = passwordEditText.getText().toString().trim();
            UserServiceImpl.login(LoginActivity.this, username, password);
//            Toast.makeText(LoginActivity.this, "登录中……", Toast.LENGTH_SHORT).show();
        });

        gotoRegisterButton.setOnClickListener(view -> {
                Intent intent = new Intent(this, RegisterActivity.class);
                startActivity(intent);
        });

//        NetworkUtils networkUtils = new NetworkUtils(LoginActivity.this);
//
//        // 检查网络是否已连接
//        networkUtils.isNetworkConnected();
//
//        // 检查网络是否可用（包括连通性和互联网连接）
//        networkUtils.isInternetAvailable();
    }
}